package graph;

import java.awt.*;
import java.awt.image.*;
import java.awt.geom.*;

import javax.imageio.*;

import zclTool.DelimitedReader;

import java.io.*;

public class StorePicture {
	public static void main_org(String[] args) {
		int width = 1000;
		int height = 1000;

		BufferedImage bi = new BufferedImage(width, height,
				BufferedImage.TYPE_INT_RGB);
		Graphics2D g3 = bi.createGraphics();
		g3.setColor(Color.white);
		for (int i = 0; i < width; i++) {
			for (int j = 0; j < height; j++) {
				g3.draw(new Ellipse2D.Double(i, j, 0, 0));
			}
		}

		try {
			DelimitedReader dr = new DelimitedReader("drawMatrix");
			String line[];
			while ((line = dr.read()) != null) {
				int id1 = Integer.parseInt(line[0]);
				int id2 = Integer.parseInt(line[1]);

				double val = Double.parseDouble(line[2]);
				int s = 255 - (int) Math.round(255 * val);
				Color c = new Color(s, s, s);
				// if(id1 == id2){
				// System.out.println(s);
				// }

				g3.setColor(c);
				g3.draw(new Ellipse2D.Double(id1, id2, 0, 0));
			}
			// System.out.println(sum);
			dr.close();
			// draw some lines

		} catch (Exception e) {

		}
		File f = new File("org.png");
		try {
			// png is an image format (like gif or jpg)
			ImageIO.write(bi, "png", f);
		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}

	public static void main_20(String[] args) {
		int width = 530;
		int height = 530;

		BufferedImage bi = new BufferedImage(width, height,
				BufferedImage.TYPE_INT_RGB);
		Graphics2D g3 = bi.createGraphics();
		g3.setColor(Color.white);
		for (int i = 0; i < width; i++) {
			for (int j = 0; j < height; j++) {
				g3.draw(new Ellipse2D.Double(i, j, 0, 0));
			}
		}

		try {
			DelimitedReader dr = new DelimitedReader("drawMatrix_20");
			String line[];
			while ((line = dr.read()) != null) {
				int id1 = Integer.parseInt(line[0]);
				int id2 = Integer.parseInt(line[1]);

				double val = Double.parseDouble(line[2]);
				int s = 255 - (int) Math.round(255 * val);
				Color c = new Color(s, s, s);
				// if(id1 == id2){
				// System.out.println(s);
				// }

				g3.setColor(c);
				g3.draw(new Ellipse2D.Double(id1, id2, 0, 0));
			}
			// System.out.println(sum);
			dr.close();
			// draw some lines

		} catch (Exception e) {

		}
		File f = new File("org_20.png");
		try {
			// png is an image format (like gif or jpg)
			ImageIO.write(bi, "png", f);
		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}

	public static void main(String[] args) {
		int width = 1000;
		int height = 1000;

		BufferedImage bi = new BufferedImage(width, height,
				BufferedImage.TYPE_INT_RGB);
		Graphics2D g3 = bi.createGraphics();
		g3.setColor(Color.white);
		for (int i = 0; i < width; i++) {
			for (int j = 0; j < height; j++) {
				g3.draw(new Ellipse2D.Double(i, j, 0, 0));
			}
		}

		try {

			DelimitedReader dr = new DelimitedReader("drawMatrix");
			String line[];
			while ((line = dr.read()) != null) {
				int id1 = Integer.parseInt(line[0]);
				int id2 = Integer.parseInt(line[1]);

				double val = Double.parseDouble(line[2]);
				int s = 255 - (int) Math.round(255 * val);
				Color c = new Color(s, s, s);
				// if(id1 == id2){
				// System.out.println(s);
				// }

				g3.setColor(c);
				g3.draw(new Ellipse2D.Double(id1, id2, 0, 0));
			}
			// System.out.println(sum);
			dr.close();
			// draw some lines

			g3.setColor(Color.red);
			dr = new DelimitedReader("border");
			while ((line = dr.read()) != null) {
				int a = Integer.parseInt(line[0]);
				for (int j = 1; j < 1200; j++) {
					if (j / 5 % 2 == 0)
						continue;
					g3.draw(new Ellipse2D.Double(a, j, 0, 0));
				}
				for (int i = 1; i < 1200; i++) {
					if (i / 5 % 2 == 0)
						continue;
					g3.draw(new Ellipse2D.Double(i, a, 0, 0));
				}

			}

		} catch (Exception e) {

		}
		File f = new File("box.png");
		try {
			// png is an image format (like gif or jpg)
			ImageIO.write(bi, "png", f);
		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}

	public static void main_grid(String[] args) {
		int width = 1000;
		int height = 1000;

		BufferedImage bi = new BufferedImage(width, height,
				BufferedImage.TYPE_INT_RGB);
		Graphics2D g3 = bi.createGraphics();
		g3.setColor(Color.white);
		for (int i = 0; i < width; i++) {
			for (int j = 0; j < height; j++) {
				g3.draw(new Ellipse2D.Double(i, j, 0, 0));
			}
		}

		try {

			DelimitedReader dr = new DelimitedReader("drawMatrix");
			String line[];
			while ((line = dr.read()) != null) {
				int id1 = Integer.parseInt(line[0]);
				int id2 = Integer.parseInt(line[1]);

				double val = Double.parseDouble(line[2]);
				int s = 255 - (int) Math.round(255 * val);
				Color c = new Color(s, s, s);
				// if(id1 == id2){
				// System.out.println(s);
				// }

				g3.setColor(c);
				g3.draw(new Ellipse2D.Double(id1, id2, 0, 0));
			}
			// System.out.println(sum);
			dr.close();
			// draw some lines
			g3.setColor(Color.red);
			for (int i = 0; i < 10; i++) {
				for (int j = 1; j < 1000; j++) {
					if (j / 10 % 2 == 0)
						continue;
					g3.draw(new Ellipse2D.Double(i * 100, j, 0, 0));
				}
			}
			for (int j = 0; j < 10; j++) {
				for (int i = 1; i < 1000; i++) {
					if (i / 10 % 2 == 0)
						continue;
					g3.draw(new Ellipse2D.Double(i, j * 100, 0, 0));
				}
			}
		} catch (Exception e) {

		}
		File f = new File("grid.png");
		try {
			// png is an image format (like gif or jpg)
			ImageIO.write(bi, "png", f);
		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}
}
